<?php

namespace App\Http\Controllers\Home;

use App\Models\Depart;
use App\Models\Doctor;
use App\Models\Setting;
use App\Models\User;
use App\Models\Worktime;
use App\Support\Wechat\WechatLogin;


class IndexController extends BaseController
{

    public function __construct(Worktime $worktime , Doctor $doctor,Depart $depart,Setting $setting,User $user)
    {
        parent::__construct();
        $this->doctor = $doctor;
        $this->depart = $depart;
        $this->worktime = $worktime;
        $this->setting = $setting;
        $this->user = $user;
    }

    public function getOauth2(){
//        $code = request('code');
//        $wechat = $this->setting->getSetting('wechat');
//        $weixin = new WechatLogin($wechat['app_id'], $wechat['app_secret']);
//        if (!isset($code)){
//            $weixin->getCode(url('auth'));
//        }else{
//            $userInfo = $weixin->get_user_info($code);
//            $this->user->wechatLogin($userInfo,request('type'));
//        }
        $mid = 3;
        $type = request('type');
        $url = url('/').'/home.html?mid='.$mid.'&token='.md5(date('Ymd',time()).'_'.$mid);
        if ($type) {
            $url = url('/').'/member_index.html?mid='.$mid.'&token='.md5(date('Ymd',time()).'_'.$mid);
        }
        Header("Location: $url");
    }


    // 获取首页数据
    public function getDoctorList()
    {
        $data = [];
        $timeArr = [];
        for($i=1;$i<=7;$i++){
            $date = date("Y-m-d",strtotime("+".$i." day"));
            $timeArr[$i]['date'] = date("m-d",strtotime($date));
            $timeArr[$i]['week_name'] = get_week($date);
        }
         $doctorList = $this->doctor->lstDateDoctor(request());
         $data['timeArr'] = $timeArr;
         $data['doctorlist'] = $doctorList;
         return ajax_return($data);
    }


    // 获取科室列表
    public function getDepartList()
    {
        $res = $this->depart->getCacheCategoryList();
        return ajax_return($res);
    }

}
